﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Directory.Web
{
    public partial class Admin_Default : System.Web.UI.Page
    {
        const string categoryIdKey = "categoryid";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!WebUtil.IsAdmin(HttpContext.Current))
            {
                Response.Redirect(FormsAuthentication.DefaultUrl);
            }
            string type = null;
            try
            {
                type = Request.QueryString["type"].Trim().ToLower();
            }
            catch { }

            this.HideAllControls();
            switch (type)
            {
                case "itemview":
                    this.ItemView.Visible = true;
                    break;
                case "categoryview":
                    this.CategoryView.Visible = true;
                    int catid;
                    if (int.TryParse(Request.QueryString[categoryIdKey], out catid))
                    {
                        if (CategoryDataProxy.GetCategory(catid) != null)
                        {
                            ClientScript.RegisterClientScriptBlock(this.GetType(), null, "<script>SetFrame('CategoryView.aspx?categoryid=" + catid.ToString() + "')</script>");
                        }
                    }
                    break;
                case "messageboard":
                    this.MessageBoard.Visible = true;
                    break;
                case "security":
                    this.Security.Visible = true;
                    break;
                case "sitesettings":
                    this.SiteSettings.Visible = true;
                    break;
                case "manual":
                    this.Manual.Visible = true;
                    break;
                default:
                    this.ItemView.Visible = true;
                    break;
            }

        }

        private void HideAllControls()
        {
            this.ItemView.Visible = false;
            this.CategoryView.Visible = false;
            this.MessageBoard.Visible = false;
            this.Security.Visible = false;
            this.SiteSettings.Visible = false;
            this.Manual.Visible = false;
        }
    }
}